package com.hengyi.webcrawler.pipeline;

import cn.hutool.crypto.SecureUtil;
import com.hengyi.webcrawler.service.IMatchService;
import com.hengyi.webcrawler.entity.Match;
import com.hengyi.webcrawler.utils.CommonUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.pipeline.Pipeline;

import java.util.List;

/**
 * @author dongzp
 * @version ChildHealthPipeline, 2019/11/5 16:01
 */
@Component
public class MatchPipeline implements Pipeline {

    @Autowired
    private IMatchService matchService;

    @Override
    public void process(ResultItems resultItems, Task task) {
        List<Match> matchList = resultItems.get("match");
        for(Match match : matchList){
            match.setId(CommonUtils.getMatchId(match));
            match.setMatchType(0);
            match.setUpdateTime(System.currentTimeMillis());
        }
        matchService.saveOrUpdateBatch(matchList);
    }
}
